import { param2Obj } from '@/utils'

const userMap = {
  'study-dev': {
    roles: ['admin'],
    token: 'a943d404-bf79-4cc2-93d7-d1acb79ed5fb',
    introduction: '我是超级管理员',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Super Admin'
  },
  'editor': {
    roles: ['editor'],
    token: 'editor',
    introduction: '我是编辑',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Normal Editor'
  }
}

export default {

  getLoginToken: config => {
    console.log(config)
    // const { username } = JSON.parse(config.body)
    // return { code: 200, message: 'success', data: userMap[username] }
    return { code: 200, message: 'success', data: { 'token': 'a943d404-bf79-4cc2-93d7-d1acb79ed5fb' }}
    // return userMap[username]
  },
  getUserInfo: config => {
    // console.log(config)
    // const { token } = param2Obj(config.url)
    return { code: 200, message: 'success', data: userMap['study-dev'] }
    // if (userMap[token]) {
    //   return { code: 200, message: 'success', data: userMap[token] }
    //   // return userMap[token]
    // } else {
    //   return { code: 401, message: '没有权限', data: null }
    // }
  },
  logout: () => { return { code: 200, message: 'success', data: null } }
}
